import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children:[
      {path:"/",redirect:"/users"},
      {path:"/users",component: () => import('../components/user.vue')},
      {path:"/roles",component: () => import('../components/juese.vue')},
      {path:"/rights",component: () => import('../components/quanxian.vue')},
      {path:"/goods",component: () => import('../components/splb.vue')},
      {path:"/params",component: () => import('../components/flcs.vue')},
      {path:"/categories",component: () => import('../components/spfl.vue')},
      {path:"/orders",component: () => import('../components/ddlb.vue')},
      {path:"/reports",component: () => import('../components/sjbb.vue')},
    ]
  },
  {
    path: '/login',
    name: 'Login',
    
    component: () => import('../views/Login.vue')
  }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to,from,next)=>{
  if (to.path=="/Login") {
    next();
  }else{
    if(sessionStorage.getItem("token")){
          next()
      }else{
        next("/Login")
      }
  }
})

export default router
